<?php

namespace app\admin\controller;


/*
 * 敏感词操作类
 * */
class Keywords extends Base
{
    protected $model;

    protected function initialize()
    {
        parent::initialize();
        $this->model = \app\common\model\Keywords::getInstance();
    }

    /*
     * 校验敏感词
     * @param content  纯文本内容
     * return  处理结果 ：data 为空代表未检测出包含敏感词，不为空 data为包含了那些敏感词
     * */
    public function checkTxt(){
        $content = $this->request->param("content") ?? "";
        if(empty($content)){
            return $this->error("请提供需要检测的内容");
        }
        //查询可用的敏感词列表
        $keyword_list = $this->model->field(['keywords'])->where(['state'=>1])->select();
        $temp = [];
        foreach ($keyword_list as $k =>$keyword){
           if(false !== strstr($content,$keyword['keywords'])){
               $temp[] = $keyword['keywords'];
           }
        }
        return $this->success("SUCCESS",$temp);
    }

}